Repository navigation
Reimplement UpdatePriest, UpdateMerchantHorse and UpdatePikeman from gynt's units branch, under /GL (100%) - #512
Merged
Conversation
Units::UpdatePriest, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (b389b78 at 63.25%, after 525a6eb at 57.72%), through our dev branch (99.9% on main before sourcehold#378). Against the dev branch's file: - the walk to the unit to bless reads the unit through the slot global from its first line, call arguments included, with no assignment to `unitID` in it. changeDestinationByAmount, which sourcehold#378 brought to main's /GL list, is then visible to the compiler and leaves the slot alone; - `animationSheetFrameOffset = 1` stands in front of `field_0x30_animRelated = 16` in both arms of that walk; - `destinationNeeded` at the end of the preaching state goes through the global. The rest is the dev branch's: `stateBasedSpeed = 0` written in front of the priest count, the campfire and inn walks through the global, and one call argument through the global for the registers at the top. The states 2, 3, 9, 11, 108 and 121 use UnitState's names, the fade's direction is written -2 as in main's UpdateMerchant, and nothing is cast to short on its way into a short field. compiler-flags-gl.txt gets UpdatePriest.cpp. IncrementAndOptionalUpdateAVValueRelated.cpp, a callee the unit has to see, is on main's list already (sourcehold#416). Real builds on main 655adce, every listed file's function resolver and all data resolvers on. A small one: main's /GL list plus this branch's four lines (main's UpdateGateHouseLarge and UpdateGateHouseSmall left out: they don't compile on 655adce), with an earlier spelling of UpdatePikeman. A full one: every file at this branch's head against main alone (main's 12 files that don't compile on 655adce left out). UpdatePriest reads 100.0% raw and normalised in both, with no differing line in the small one, and nothing on main reads lower in the full one. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Units::UpdateMerchantHorse, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (4b7d935 at 46.84%, after e103100 at 41.35%), through our dev branch (99.1% on main before sourcehold#378). Against the dev branch's file, one store: `updateTickTracker = 0`, the last store in front of resetUnitMovementState, goes through the slot global. With commitUnitLocation's callees visible (setupUnitSharingTileIDs, which sourcehold#378 brought to main's /GL list, and setupUnitSharingCurrentTilePosition), the compiler then sets up resetUnitMovementState's argument above the last store only, as the original does. The rest is the dev branch's, with one call argument through the global for the registers at the top. The states 2 and 3 use UnitState's names, also where they are stored into cachedState, and the fade's direction is written -2 as in main's UpdateMerchant. compiler-flags-gl.txt gets UpdateMerchantHorse.cpp. Real builds on main 655adce, every listed file's function resolver and all data resolvers on. A small one: main's /GL list plus this branch's four lines (main's UpdateGateHouseLarge and UpdateGateHouseSmall left out: they don't compile on 655adce), with an earlier spelling of UpdatePikeman. A full one: every file at this branch's head against main alone (main's 12 files that don't compile on 655adce left out). UpdateMerchantHorse reads 100.0% raw and normalised in both, with no differing line in the small one, and nothing on main reads lower in the full one. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Units::UpdatePikeman, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (4630f86 at 41.54%), through our dev branches (99.9% on main before sourcehold#378). The forms that matter: - `int building = 0;` with the function's locals and no local copy of the unit ID, as in UpdateKnight (sourcehold#444): the original's 4 bytes of frame that are never touched and its zero register for a wall; - the dig-moat block behind setDestinationForUnit reads the unit through the slot global, call argument included. With changeDestinationByAmount's body visible (sourcehold#378 brought it to main's /GL list) the compiler knows the call leaves the slot alone and stores the dig tile's X and Y in front of the pops, as the original does (0x0055F2AB, 0x0055F2B2). The states 2, 3 and 108 use UnitState's names; 105 and 124 have none on main and keep their casts. State 0's choice between 2 and IDLE, the thrust picture's and the damage are if / else (main's style-lint flags a ternary). The AI's wall-danger test reads `attackInfo.playerInfo[attacker - 1]` (currentPlayerID_OR_attackedPlayerID_OR_one and someMinimumDistance) and `SEC_PathfindingCostTileMap1105`, where main's header now has these blocks (they were raw offsets before); the LogicLayer masks use Logic1's names and the two orientation tests CD_UNSPECIFIED. The hit sound keeps getBuildingHurtSFXID's result as a HitSoundMaterialInt and compares it with HSM_WOOD and HSM_STONE, as UpdateArabianSwordsman does. Nothing is cast to short on its way into a short field or on a read of a short layer, steps by one are ++ / --, and the gate-or-tower test for the damage is a truth test, as in the AI's test below it. advanceMoatDigProgress and removeMoat return BOOLEnum, but their results stay compared with 1: the original has `cmp eax, 1` there (0x0055FC1F, 0x0055FE11), and a truth test gives `test eax, eax`. compiler-flags-gl.txt gets UpdatePikeman.cpp and ViewportRenderState/xyAreValid.cpp, a callee the unit has to see (100% on main). Real builds on main 655adce, every listed file's function resolver and all data resolvers on. A small one: main's /GL list plus this branch's four lines (main's UpdateGateHouseLarge and UpdateGateHouseSmall left out: they don't compile on 655adce), on this text. A full one: every file, on an earlier spelling of this file that differs only in names and spellings and gives the same listing, against main alone (main's 12 files that don't compile on 655adce left out). UpdatePikeman and xyAreValid read 100.0% raw and normalised in both, with no differing line in the small one, and nothing on main reads lower in the full one. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gynt
approved these changes
Nov 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three more Map::Units update functions at 100%, from gynt's units branch
reimpl/map-units-updatefunctions(his draft #204). They waited for #378: each one keeps values in registers across a call into one of the UnitsState functions that #378 put on the/GLlist, so it only matches once the compiler can see that callee's body. Each commit cites the draft it builds on and credits gynt as co-author. No header changes.Units::UpdatePriest/GLUnits::UpdateMerchantHorse/GLUnits::UpdatePikeman/GLMeasured.
Stronghold Crusader.exe(3bb0a8c1…5387ac5a), both resolver sets enabled locally (not committed), and sourcehold's reccmp (a86aceb03) with--resolve-wrapped-calls --ignore-security-cookie./GLlist with this branch's four lines (253 files, every listed file's resolver on), rerun on this head. All three read 100.0% raw and normalised with no differing line, and so doesxyAreValid.HitSoundMaterialnames, the damage as if / else,break;at the end of the last case, comments and a blank line), and its listing in the small build is the same, so the result stands. Both built with 0 failures, 2,907 and 2,910 files, and reccmp averages 99.54% over 2,925 and 2,928 functions. The three units come in at 100.0% raw and normalised, andxyAreValidstays at 100.0% on the/GLlist. Nothing on main reads lower. The only other changes areUI::Menu::Constructor_Menu(98.4% to 100%) andhandleMenuItems(97.9% to 100%). Earlier full builds where neither file changed showed the same jump, so it follows where functions land in the image. This PR doesn't touch them. The 12 main files listed under Other PRs were left out of both builds.openshc-pr-fixfinds nothing to change, andopenshc-pr-checkgives 0 errors and 89 notes, all of the kinds below.What got them to 100%
All three started from gynt's drafts and went through our development branches, where they reached 99.1-99.9% on main before #378. What was left in each was a value the original keeps in a register across a call into a function whose body the compiler could not see yet.
DAT_CurrentUnitSlotIDfrom its first line, call arguments included, and doesn't assignunitIDthere. WithchangeDestinationByAmountvisible, the compiler knows the call leaves the slot alone and keeps it where the original does. In both arms of that walkanimationSheetFrameOffset = 1comes beforefield_0x30_animRelated = 16, anddestinationNeededat the end of the preaching state goes through the slot too.IncrementAndOptionalUpdateAVValueRelated, the other callee it has to see, has been on main's list since Five more functions at 100%: InGameMenu MainButtons, Roundtable handler, BuySell, UpdateGhost and UpdateHopsFarmer #416.updateTickTracker = 0, the last store beforeresetUnitMovementState, goes through the slot. WithcommitUnitLocation's callees visible (setupUnitSharingTileIDsfrom Reimplement 47 UnitsState functions at 100% and restyle 28 more #378 andsetupUnitSharingCurrentTilePosition), the compiler then sets upresetUnitMovementState's argument above that store only, as the original does.int building = 0;sits with the function's locals and there is no local copy of the unit ID, as in UpdateKnight (One more Map::Units function at 100%: UpdateKnight #444). That gives the original's 4 bytes of frame that are never touched and its zero register for a wall. The dig-moat block aftersetDestinationForUnitreads the unit through the slot, call argument included. WithchangeDestinationByAmountvisible, the compiler stores the dig tile's X and Y before the pops, as the original does (0x0055F2AB, 0x0055F2B2).UnitState's names where main has one (2, 3, 9, 11, 108 and 121 in UpdatePriest, 2 and 3 in UpdateMerchantHorse, 2, 3 and 108 in UpdatePikeman), and in UpdatePriest and UpdateMerchantHorse the fade step is written -2, as in main's UpdateMerchant.Names from main's newer headers
The drafts and our earlier texts were written against older headers. This branch uses what main declares now:
attackInfo. Main'sAttackInfonow has the per-player blocks (playerInfo[8], 96188 bytes each, from 0x4797C), so the test readsattackInfo.playerInfo[attacker - 1].currentPlayerID_OR_attackedPlayerID_OR_oneand.someMinimumDistance. The byte it compares isDAT_TileMapState::instance.SEC_PathfindingCostTileMap1105[player][tile], which used to be written asplayer * 80400 + 0x1EE2998 + tile.Logic1's names (L_WALL_OR_GATEHOUSE,L_MOAT,L_WALL_OR_GATEHOUSE | L_KEEP_NON_MANOR_HOUSE), and the two orientation tests useCD_UNSPECIFIED, as in Reimplement 47 UnitsState functions at 100% and restyle 28 more #378.getBuildingHurtSFXID's result as aHitSoundMaterialIntnamedmaterialand compares it withHSM_WOODandHSM_STONE, as main's UpdateArabianSwordsman does.Code generation is the same.
Four lines added to
cmake/compiler-flags-gl.txtUpdatePriest.cpp,UpdateMerchantHorse.cppandUpdatePikeman.cpp: the units themselves. Under/GL, they see their callees' bodies that main's list already has (changeDestinationByAmount,setupUnitSharingTileIDs,commitUnitLocation,hasUnitReachedDestination,IncrementAndOptionalUpdateAVValueRelatedand others).Rendering/ViewportRenderState/xyAreValid.cpp: a callee UpdatePikeman has to see. It is 100% on main and was on no list. It reads 100.0% on the list too.Kept as they are
(UnitState)105and(UnitState)124in UpdatePikeman. Main'sUnitStatehas no names for them yet (see below).(char)casts onUnit::disappearFadeAlphaCountdown,Unit::engineerManningSiegeStateRef_checkTypeand the AnimationFrameData tables, as in Reimplement 5 Map::Units update functions from gynt's units branch, under /GL (100%) #393 and Reimplement 4 Map::Units functions and RenderAnimatedTutorialFloatOverlay, with UnitState names (100%) #409. The fields arebytein the headers, but the original reads them as signed (movsx,< 0,> 32).(short)on both sides of one difference in UpdatePikeman's moat-filling block (targetedBuildingTileminustranslationMatrix[...].addXgetTile, stored into the unit's short dig tile X). The other(short)casts are gone: main's header hasBuildingLayerandUnitLayerasshortnow, and a store into a short field needs none.(int)(mapTimeInTicks + slot) % 40in UpdatePikeman.GameCore::mapTimeInTicksis auint, and the original takes a signed remainder, as in UpdateKnight and the other unit functions on main.int damage;andint thrustGfx;are declared before the if / else chain that sets them on every path.advanceMoatDigProgress(...) == 1andremoveMoat(...) != 1in UpdatePikeman stay comparisons with 1, each with a one-line comment. Both returnBOOLEnum, but the original compares the result with 1 (cmp eax, 1at 0x0055FC1F and 0x0055FE11). We tried truth tests: they compile totest eax, eaxand lose the match.moat > -1in UpdatePikeman's two moat orders stays as it is: the original compares with -1 (cmp reg, -1/jle), andmoat >= 0givestest/jl.IsGateOrTowerArray[...]is aBOOLEnumarray, so it is a truth test.isDisappearingUnk,goToRallyPoint,isSelected,seatedandkilledFlagUnkareshortfields inUnit.hpp, so they keep!= 0.int attackedsits in UpdatePikeman's first line: the original reads the unit'sattackedUnitIDthere, beforeaddUnitToNewTribe, and the melee state uses that value for the height difference, so it stays up there.int attackerin UpdatePikeman's wall attack is the unit'sownerread again after the calls, as the original does, rather than theownerread at the top.int const churchTypein UpdatePriest is read before the stores in front of the switch, as the original reads it.field_0x58 = 1in UpdatePikeman stays a number. The checker matches the name to aBOOLEnumfield ofSoundEffectsHelperData1, butUnit::field_0x58is ashort.field_0x3f4,field_0x5d28, ...), which we have nothing better for.Proposed, not changed here
US_UNKNOWN_105andUS_UNKNOWN_124inUnitState. UpdatePikeman's state switch (cmp eax, 0x7dat 0x0055F175, byte table 0x00560680, jump table 0x00560638) gives 105 an arm of its own (0x0055F474) and sends 124 to the arm of state 4,US_RELOAD_WEAPONUnk(0x0055FA7C). The original stores 105 at 0x0055F1E8 and 124 at 0x0055F2CC and 0x0055FA81 (mov word ptr [reg + 0x138880C], the units array plusstate). Left out so that this PR needs no header sync.intresults foradvanceMoatDigProgressandremoveMoat. Both returnBOOLEnuminTileMapState.hpp, but UpdatePikeman compares their results with 1 rather than testing them, which reads like anintresult.US_DIG(125) is the state the pikeman's fill-moat order (UIT_FILL_MOAT) sets, and it fills the moat withremoveMoat(commented "filling a moat" here; main's UpdateAssassin sets it for a moat to fill too). 124, set by the dig-moat order (UIT_DIG_MOAT), is the one that digs, withadvanceMoatDigProgress. SoUS_DIGreads better as a fill state, and 124 could take the dig name.(char)casts above: retyping those fields tocharin Ghidra would let the casts go here and in the unit functions on main (Reimplement 5 Map::Units update functions from gynt's units branch, under /GL (100%) #393 and Reimplement 4 Map::Units functions and RenderAnimatedTutorialFloatOverlay, with UnitState names (100%) #409 proposed this too).Other PRs
cmake/compiler-flags-gl.txt, so whichever goes in second gets a one-line conflict there: keep both.Building'spathLinkageRelated2andgateState:renderDebugDataCurrentPlayerData,applyGateOrDrawbridgeOpenCloseChange,initializeGatePathfindingForOwner,updatePathLinkageTileMap,UpdateGateHouseLarge,UpdateGateHouseSmall,UpdateWoodGate1,findBestAttackTileByPathCost,resetTileAndClearMoat,GateOpenOrClose,ClickOpenOrCloseGate,TransformAndRenderPercentage. Both builds above left them out, with their resolvers off. This PR doesn't touch them.🤖 Generated with Claude Code